package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.pojo.Courier;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.user.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description AdminOrderController
 * @Author lyh
 * @Date 2024-10-19
 */
@RestController
@Api(tags = "商家订单管理")
@RequestMapping("/admin/order")
public class AdminOrderController {
    @Autowired
    private OrderService orderService;

    /**
     * 分页查询
     * @param dto
     * @return
     */
    @GetMapping("/conditionSearch")
    @ApiOperation("分页查询")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO dto){
      PageResult pageResult=orderService.conditionSearch(dto);
      return Result.success(pageResult);
    }
    @GetMapping("/statistics")
    @ApiOperation("各个状态的订单数量统计")
    public Result<OrderStatisticsVO> countStatus(){
        OrderStatisticsVO orderStatisticsVO=orderService.countStatus();
        return Result.success(orderStatisticsVO);
    }
    @GetMapping("/details/{orderId}")
    @ApiOperation("查看订单详情")
    public Result<OrderVO> adminOrderDetail(@PathVariable Long orderId){
       OrderVO orderVo=orderService.adminOrderDetail(orderId);
       return Result.success(orderVo);
    }
   @PutMapping("/cancel")
   @ApiOperation("取消订单")
    public Result cancelingOrders(@RequestBody OrdersCancelDTO dto){
       orderService.cancelingOrders(dto);
       return Result.success();
    }
    @PutMapping("/rejection")
    @ApiOperation("商家拒单")
    public Result rejectionOrder(@RequestBody OrdersRejectionDTO dto){
      orderService.rejectionOrder(dto);
      return Result.success();
    }
    @PutMapping("/confirm")
    @ApiOperation("商家接单")
    public Result<Courier> confirm(@RequestBody OrdersConfirmDTO dto){
        Courier courier=orderService.confirm(dto);
        return Result.success(courier);
    }
    @PutMapping("/shipment/{orderId}")
    @ApiOperation("商家出餐")
    public Result<String> shipment(@PathVariable Long orderId){
        return Result.success();
    }
}
